#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > hfreqfromg.info <<'%EOF%'
   hfreqfromg
   ----------
   Molecule:         H2O
   Wave Function:    SCF / cc-pVDZ
   Test Purpose:     Harmonic frequencies calculated numerically from
                     gradients
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > hfreqfromg.mol <<'%EOF%'
BASIS                                 
STO-3G
NH3

    2    0
        7.    1
N          0.0000019235            0.0000000101            0.8537220513
        1.    3
H         -1.7773989973           -0.0000000217            0.0487589947
H          0.8886985392            1.5392766387            0.0487594789
H          0.8886985114           -1.5392766339            0.0487594750
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > hfreqfromg.dal <<'%EOF%'
**DALTON INPUT
.NMDDRV
**NMDDRV
.DORDR
  1  1
.SYMMETRY
  C3v
.NORMAL COORDINATES
**WAVE FUNCTIONS
.HF
*SCF INP
.THRESH
 1.0D-8
**PROPERTIES
.SPIN-SPIN
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >hfreqfromg.check
cat >>hfreqfromg.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Starting geometry and energy
CRIT1=`$GREP "Final * HF energy\: * \-55\.45541977925." $log | wc -l`
CRIT2=`$GREP "Nuclear repulsion\: * 11\.73718079440." $log | wc -l`
CRIT3=`$GREP "Electronic energy\: * \-67\.19260057365." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=6
ERROR[1]="STARTING GEOMETRY/ENERGY NOT CORRECT"

# Symmetry input.
CRIT1=`$GREP "1\. irep\:" $log | wc -l`
CRIT2=`$GREP "1\.00 * 1\.00 * 1\.00 * 1\.00 * 1\.00 * 1\.00" $log | wc -l`
CRIT3=`$GREP "2\. irep\:" $log | wc -l`
CRIT4=`$GREP "1\.00 * 1\.00 * 1\.00 \-1\.00 \-1\.00 \-1\.00" $log | wc -l`
CRIT5=`$GREP "3\. irep\:" $log | wc -l`
CRIT6=`$GREP "1\.00 (\-0| \-)\.50 (\-0| \-)\.50 * 1\.00 (\-0| \-)\.50 (\-0| \-)\.50" $log | wc -l`
CRIT7=`$GREP "(0| )\.00 * (0| )\.87 (\-0| \-)\.87 * (0| )\.00 * (0| )\.87 (\-0| \-)\.87" $log | wc -l`
CRIT8=`$GREP "(0| )\.00 (\-0| \-)\.87 * (0| )\.87 * (0| )\.00 * (0| )\.87 (\-0| \-)\.87" $log | wc -l`
CRIT9=`$GREP "1\.00 (\-0| \-)\.50 (\-0| \-)\.50 \-1\.00 * (0| )\.50 * (0| )\.50" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[2]=12
ERROR[2]="SYMMETRY INPUT NOT CORRECT"

# Hessian
CRIT1=`$GREP "1/ *1 * (0| )\.336[0-9][0-9][0-9]" $log | wc -l`
CRIT2=`$GREP "1/ *2 * (\-0| \-)\.251[0-9][0-9][0-9] * (0| )\.500[0-9][0-9][0-9]" $log | wc -l`
CRIT3=`$GREP "1/ *3 * (\-0| \-)\.194[0-9][0-9][0-9] * (0| )\.144[0-9][0-9][0-9] * (0| )\.112[0-9][0-9][0-9]" $log | wc -l`
CRIT4=`$GREP "2/ *4 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9]" $log | wc -l`
CRIT5=`$GREP "3/ *5 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (0| )\.840[0-9][0-9][0-9]" $log | wc -l`
CRIT6=`$GREP "3/ *6 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0| \-)\.568[0-9][0-9][0-9] * (0| )\.499[0-9][0-9][0-9]" $log | wc -l`
CRIT7=`$GREP "3/ *7 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0| \-)\.31[0-1][0-9][0-9][0-9] * (0| )\.210[0-9][0-9][0-9]" $log | wc -l`
CRIT8=`$GREP "3/ *8 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|\-)\.118[0-9][0-9][0-9] * (\-0| \-)\.036[0-9][0-9][0-9]" $log | wc -l`
CRIT9=`$GREP "3/ *7 * (0| )\.114[0-9][0-9][0-9]" $log | wc -l`
CRIT10=`$GREP "3/ *8 * (0| )\.043[0-9][0-9][0-9] * (0| )\.132[0-9][0-9][0-9]" $log | wc -l`
CRIT11=`$GREP "3/ *9 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (0| )\.840[0-9][0-9][0-9]" $log | wc -l`
CRIT12=`$GREP "3/ *10 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0| \-)\.568[0-9][0-9][0-9] * (0| )\.499[0-9][0-9][0-9]" $log | wc -l`
CRIT13=`$GREP "3/ *11 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|\-)\.31[0-1][0-9][0-9][0-9] * (0| )\.210[0-9][0-9][0-9] * (0| )\.114[0-9][0-9][0-9]" $log | wc -l`

CRIT14=`$GREP "3/ *12 * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0|0|\-| )\.000[0-9][0-9][0-9] * (\-0| \-)\.118[0-9][0-9][0-9] * (\-0| \-)\.036[0-9][0-9][0-9] * (0| )\.043[0-9][0-9][0-9] * (0| )\.132[0-9][0-9][0-9]" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
		$CRIT13 \+ $CRIT14`
CTRL[3]=14
ERROR[3]="HESSIAN NOT CORRECT"

# Frequencies and normal coordinates.
CRIT1=`$GREP "1 * 3833\.[0-9][0-9] * (0| )\.0174[0-9][0-9]" $log | wc -l`
CRIT2=`$GREP "1 * 1411\.[0-9][0-9] * (0| )\.0064[0-9][0-9]" $log | wc -l`
CRIT3=`$GREP "3 * 2076\.[0-9][0-9] * (0| )\.0094[0-9][0-9]" $log | wc -l`
CRIT4=`$GREP "3 * 4108\.[0-9][0-9] * (0| )\.0187[0-9][0-9]" $log | wc -l`
CRIT5=`$GREP "Number of gradient calculations done\: * 25" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[4]=7
ERROR[4]="FREQUENCIES AND NORMAL COORDINATES NOT CORRECT"

PASSED=1
for i in 1 2 3 4 
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
